package org.wevil.repo.sys;

import org.wevil.entity.sys.SysRole;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.wevil.repo.BaseRepo;

import java.util.List;

public interface SysRoleRepo extends BaseRepo<SysRole, Integer> {

    @Query("from SysRole where id in ?1")
    List<SysRole> findByRoleIdIn(List<Integer> roleIds);

    @Query("select name from SysRole where id in ?1")
    List<String> findRoleNameByRoleIdIn(List<Integer> roleIds);

    @Modifying
    @Query("update SysRole t set " +
            "t.name = case when :#{#entity.name} is null then t.name else :#{#entity.name} end, " +
            "t.desc = case when :#{#entity.desc} is null then t.desc else :#{#entity.desc} end " +
            "where t.id = :#{#entity.id}")
    void update(SysRole entity);
}
